package com.lzl.ams.controller;

import com.alibaba.fastjson.JSON;
import com.lzl.ams.service.CodeRunner;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RequestMapping("/code")
@RestController
public class CodeController {

    @PostMapping("/run")
    public String run(@RequestParam("code") String code, @RequestParam("opts") String opts){
        Map map = JSON.parseObject(opts, Map.class);
        List<String> optsList = new ArrayList<String>();
        for(Object entry : map.entrySet()){
            optsList.add(((Map.Entry)entry).getKey()+" " + ((Map.Entry)entry).getValue());
        }
        return CodeRunner.run(code,optsList);
    }

    @GetMapping("/test")
    public String test(){
        return "testOk";
    }
}
